package com.shijianchen.aop;

import com.shijianchen.utils.Result;
import io.jsonwebtoken.ExpiredJwtException;
import io.jsonwebtoken.security.SignatureException;
import jakarta.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.NoHandlerFoundException;

//@ControllerAdvice
public class GlobalExecptionHandler {
//    private final Logger logger = LoggerFactory.getLogger(GlobalExecptionHandler.class);
//    @ResponseBody
//    @ExceptionHandler(value = SignatureException.class)
//    public Result<Object> JwtSignatureExceptionHandler(HttpServletRequest httpServletRequest, SignatureException e) {
//        logger.error("jwt signature error:", e);
//        return Result.fail(302,e.getMessage());
//    }
//    @ResponseBody
//    @ExceptionHandler(value = ExpiredJwtException.class)
//    public Result<Object> ExpiredJwtExceptionHandler(HttpServletRequest httpServletRequest, ExpiredJwtException e) {
//        logger.error("ExpiredJwtException error:", e);
//        return Result.fail(302,"token签名错误，请重新登录！");
//    }
//
//    @ResponseBody
//    @ExceptionHandler(value = NoHandlerFoundException.class)
//    public Result<Object> NoHandlerFoundExceptionHandler(HttpServletRequest httpServletRequest, NoHandlerFoundException e) {
//        logger.error("NoHandlerFoundException error:", e);
//        return Result.fail(404,"接口不存在或未定义");
//    }
//
//    @ResponseBody
//    @ExceptionHandler(value = Exception.class)
//    public Result<Object> exceptionHandler(HttpServletRequest httpServletRequest, Exception e) {
//        logger.error("exceptionHandler error:", e);
//        return Result.fail(500,e.getMessage());
//    }
}
